<template>
    <div class="container user-container">
        <div class="user">
            <header>
                <router-link to="/materialList">材料管理 / </router-link>
                {{companyName}}
            </header>
            <div v-if="messageList.length > 0" class="focus-pointer mb30">
                <div class="flex-box-align" style="padding-left: 18px; position: relative; width: 100%;">
                    今日要事：
                    <div class="message">
                        <ul class="marquee_list" :style="{ top: -num + 'px'}" :class="{marquee_top:num}">
                            <li v-for="(item, index) in messageList" :key="index" v-if="messageList && messageList.length">
                                <router-link :to="{name: item.route}">{{item.showMsg}}</router-link>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="search-modal mb30">
                <div class="" style="margin-bottom: 20px">
                    <span>查询及添加</span>
                    <el-button type="primary" size="small" @click="handleClickSearch">查询</el-button>

                </div>
                <div class="flex-box-align">
                    <div class="search-item">
                        <div class="search-title">文档名称：</div>
                        <el-input style="width: 54%;" class=""
                                  placeholder="请输入"
                                  v-model="configList.param.attachmentNameLike" ></el-input>
                    </div>
                    <div class="search-item">
                        <div class="search-title">所属订单id：</div>
                       <el-input style="width: 54%;" class=""
                                  placeholder="请输入"
                                  v-model="configList.param.orderId" ></el-input>
                    </div>
                    <div class="search-item">
                        <div class="search-title">材料大类：</div>
                        <el-select filterable @change="userTypeChange" v-model="configList.param.firstFileType" placeholder="请选择">
                            <el-option
                            label="全部"
                            value="">
                            </el-option>
                            <el-option
                            v-for="item in sortArr"
                            :key="item.key"
                            :label="item.value"
                            :value="item.key">
                            </el-option>
                        </el-select>
                    </div>
                    <div class="search-item">
                        <div class="search-title">材料小类：</div>
                        <el-select filterable v-model="configList.param.secondFileType" placeholder="请选择">
                            <el-option
                            label="全部"
                            value="">
                            </el-option>
                            <el-option
                                v-for="item in sortArr1"
                                :key="item.key"
                                :label="item.value"
                                :value="item.key">
                            </el-option>
                        </el-select>
                    </div>
                </div>
            </div>

            <div class="">
                <table-list ref="tableList" :tableConfig='configList'>
                    <el-table-column class="btn" label="操作" slot="btn" align="center" >
                        <template slot-scope="scope">
                            <a class="btn-upload" target="_blank" :href="scope.row.attachmentFileInfo.fileUrl">下载</a>
                        </template>
                    </el-table-column>
                </table-list>
            </div>
        </div>
    </div>
</template>

<script>
    import {parseUrlParams} from "../../util";
    let CONSTANT = require('../../constant/constant.js'),
        common = require('../../common.js');
    export default {
        data() {
            return {
                companyName: '',
                id:'',
                sortArr:[],
                sortArr1:[],
                configList:{
                    url:CONSTANT.URL.ATTACHMENT.FINDATTACHMENTBYCOMPANY,
                    configList:[
                        {
                            label:'文档id',
                            prop: "attachmentFileId"
                        },
                        {
                            label:'材料标题',
                            prop: "attachmentName"
                        },
                        {
                            label:'材料大类',
                            prop: "firstFileTypeDesc"
                        },
                        {
                            label:'材料小类',
                            prop: "secondFileTypeDesc"
                        },
                        {
                            label:'所属订单id',
                            prop: "orderId"
                        },
                        {
                            label:'归档时间',
                            prop: "gmtCreated"
                        },
                        {
                            slot: "btn"
                        }
                    ],
                    param:{
                        attachmentNameLike: "",
                        firstFileType: "",
                        orderId: "",
                        secondFileType: "",
                        userId: ''
                    },
                    type:'',
                    width:'',
                    isPagination:true
                },
                num: 0,
                messageList: []
            }
        },
        components: {
            'table-list':() => import('../common/my-table')
        },
        watch:{
     
        },
        mounted(){
            this.getMessage()
            setInterval( () => {
                this.getMessage()
            }, 120000)
            this.id = this.$router.currentRoute.query.id;
            this.companyName = this.$router.currentRoute.query.name;
            this.configList.param.userId = this.id;
            this.getSortList()
            this.getSortList1()
            this.handleClickSearch()
        },
        methods:{
            getMessage() {
                let url = CONSTANT.URL.CALENDAR.MESSAGELIST;
                common.requestAjax(url, {}, {}, (data) => {
                    if(data.status == 200) {
                        this.messageList = data.data.bussData;
                        this.showMarquee(this.num)
                    }
                })
            },
            handleClickSearch() {
                this.$refs.tableList && this.$refs.tableList.getList()
            },
            userTypeChange(e){
                this.configList.param.secondFileType = ''
                 this.sortArr.map((item)=>{
                     if(item.key == e){
                         this.sortArr1 = item.childs
                     }
                 })
                
            },
            getSortList(){
                let  url = CONSTANT.URL.SYS.LOADDICTIONARY,
                    data = {},
                    dataForm = {codeType:'first_file_type'}
                    common.requestAjax(url,JSON.stringify(data),dataForm,(res)=>{
                    if(res.status == 200){
                        this.sortArr= res.data.bussData
                    }else{
                    
                    }
                })
            },
            getSortList1(){
                let  url = CONSTANT.URL.SYS.LOADDICTIONARY,
                    data = {},
                    dataForm = {codeType:'second_file_type'}
                    common.requestAjax(url,JSON.stringify(data),dataForm,(res)=>{
                    if(res.status == 200){
                        this.sortArr1= res.data.bussData
                    }else{
                    
                    }
                })
            },
            showMarquee:function (num) {
                if (!this.messageList[0]) return
                this.messageList.push(this.messageList[0]);
                var max = this.messageList.length;
                var that = this;
                let marqueetimer =  setInterval(function(){
                    num++;
                    if(num>=max ){
                        num=0;
                    }
                    that.num=num*30;
                }, 2000);
            }
        }
    }
</script>

<style lang="scss" scoped>
    .container {
        &.user-container{
            .el-input,.el-select{
                width: 60%;
            }
        }
        .mb30 {
            margin-bottom: 30px;
        }
        .btn-upload{
            width: 73px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            color: #fff;
            font-size: 14px;
            border-radius: 4px;
            background-color: #ED7018;
            display: inline-block;
            cursor: pointer;
            &:hover{
                background-color: #ED9000;
                transition:all .2s linear
            } 
        }
        .user {
            header {
                margin: 19px 0;
                font-size: 14px;
                color: #333;
                a {
                    color: #999;
                }
            }
            .focus-pointer {
                font-size: 14px;
                height: 70px;
                line-height: 70px;
                background-color: #fff;
                padding-left: 18px;
                white-space: nowrap;
            }

            .search-modal {
                background: #fff;
                padding: 20px 0 25px 18px;
                .btns {
                    width: 73px;
                    height: 40px;
                    text-align: center;
                    line-height: 40px;
                    color: #fff;
                    font-size: 14px;
                    border-radius: 4px;
                    background-color: #ED7018;
                    display: inline-block;
                    cursor: pointer;
                    &:hover{
                     background-color: #ED9000;
                     transition:all .2s linear
                    }
                }
                .btn-search {
                    margin: 0 20px 0 24px;
                }
                .search-item {
                    width: 25%;
                    display: inline-block;
                    /*margin-right: 2.56%;*/
                    &:last-child {
                        margin-right: 0;
                    }
                    .search-title {
                        display: inline-block;
                    }
                    .el-input {
                        display: inline-block;
                    }
                    .el-select {
                        width: 54%;
                    }
                }
            }
        }
    }
</style>
